#!/usr/bin/env python
# coding: utf8
import socket
import threading
import logging


def on_connect(tname, socket_fd, addr_info):
    print addr_info, 'connect to me'
    socket_fd.send('OK')
    while True:
        data = socket_fd.recv(2048)
        print data


def main():
    s_fd = socket.socket()
    s_fd.bind(('0.0.0.0', 34567))
    s_fd.listen(20)
    while True:
        socket_fd, addr_info = s_fd.accept()
        thread = threading.Thread(None, on_connect, str(addr_info), (str(addr_info), socket_fd, addr_info))
        thread.start()


if __name__ == "__main__":
    main()
